<div [@routerTransition]>

    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("Languages")}}</span>
                </h3>
                <span class="m-section__sub">
                    {{l("LanguagesHeaderInfo")}}
                </span>
            </div>
            <div class="col-xs-6 text-right">
                <button *ngIf="isGranted('Pages.Administration.Languages.Create')" (click)="createOrEditLanguageModal.show()" class="btn btn-primary blue"><i class="fa fa-plus"></i> {{l("CreateNewLanguage")}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="row align-items-center">
                    <!--<Primeng-Datatable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengDatatableHelper.isLoading">
                        <p-dataTable #dataTable
                                     (onLazyLoad)="getLanguages()"
                                     [value]="primengDatatableHelper.records"
                                     rows="{{primengDatatableHelper.defaultRecordsCountPerPage}}"
                                     [paginator]="false"
                                     [lazy]="true"
                                     emptyMessage="{{l('NoData')}}"
                                     [responsive]="primengDatatableHelper.isResponsive">
                            <p-footer>
                                {{l('TotalRecordsCount', primengDatatableHelper.totalRecordsCount)}}
                            </p-footer>

                            <p-column field=""
                                      header="{{l('Actions')}}"
                                      [sortable]="false"
                                      [style]="{'width':'130px','text-align':'center'}"
                                      [hidden]="!isGrantedAny('Pages.Administration.Languages.Edit', 'Pages.Administration.Languages.ChangeTexts', 'Pages.Administration.Languages.Delete')">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <div class="btn-group dropdown">
                                        <button class="dropdown-toggle btn btn-sm btn-primary"
                                                data-toggle="dropdown"
                                                aria-haspopup="true"
                                                aria-expanded="false">
                                            <i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a *ngIf="permission.isGranted('Pages.Administration.Languages.Edit') && record.tenantId === appSession.tenantId"
                                                   (click)="createOrEditLanguageModal.show(record.id)">{{l('Edit')}}</a>
                                            </li>
                                            <li>
                                                <a *ngIf="permission.isGranted('Pages.Administration.Languages.ChangeTexts')"
                                                   (click)="changeTexts(record)">{{l('ChangeTexts')}}</a>
                                            </li>
                                            <li>
                                                <a *ngIf="permission.isGranted('Pages.Administration.Languages.Edit')"
                                                   (click)="setAsDefaultLanguage(record)">{{l('SetAsDefaultLanguage')}}</a>
                                            </li>
                                            <li>
                                                <a *ngIf="permission.isGranted('Pages.Administration.Languages.Delete') && record.tenantId === appSession.tenantId"
                                                   (click)="deleteLanguage(record)">{{l('Delete')}}</a>
                                            </li>
                                        </ul>
                                    </div>
                                </ng-template>
                            </p-column>
                            <p-column field="displayName" header="{{l('Name')}}" [sortable]="false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <span [ngClass]="{'text-bold' : defaultLanguageName === record.name}">
                                        <i [ngClass]="record.icon" class="margin-right-5"></i>
                                        {{record.displayName}} <span *ngIf="defaultLanguageName === record.name">({{l('Default')}})</span>
                                    </span>
                                </ng-template>
                            </p-column>
                            <p-column field="name" header="{{l('Code')}}" [sortable]="false"></p-column>
                            <p-column field="tenantId" header="{{l('Default')}} *" [sortable]="false" *ngIf="appSession.tenantId ? true : false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <span class="label m-badge m-badge--success m-badge--wide"
                                          *ngIf="record.tenantId !== appSession.tenantId">
                                        {{l('Yes')}}
                                    </span>
                                    <span class="label m-badge m-badge--metal m-badge--wide"
                                          *ngIf="record.tenantId === appSession.tenantId">
                                        {{l('No')}}
                                    </span>

                                </ng-template>
                            </p-column>
                            <p-column field="creationTime" header="{{l('CreationTime')}}" [sortable]="false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    {{record.creationTime | momentFormat:'L'}}
                                </ng-template>
                            </p-column>
                            <p-column field="isEnabled" header="{{l('IsEnabled')}}" [sortable]="false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <span class="label m-badge m-badge--success m-badge--wide"
                                          *ngIf="!record.isDisabled">
                                        {{l('Yes')}}
                                    </span>
                                    <span class="label m-badge m-badge--metal m-badge--wide"
                                          *ngIf="record.isDisabled">
                                        {{l('No')}}
                                    </span>
                                </ng-template>
                            </p-column>
                        </p-dataTable>
                    </div>
                    <!--<Primeng-Datatable-End>-->

                    <p class="margin-top-20" *ngIf="appSession.tenantId">
                        * {{l("CanNotEditOrDeleteDefaultLanguages")}}
                    </p>

                </div>
            </div>
        </div>
    </div>

    <createOrEditLanguageModal #createOrEditLanguageModal (modalSave)="getLanguages()"></createOrEditLanguageModal>
</div>
